﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using Caliburn.Micro.BikeWizard.Data;
using Caliburn.Micro.BikeWizard.Utils;

namespace Caliburn.Micro.BikeWizard.Services
{
    public class BikeOptionService : IBikeOptionService
    {
        #region Public Properties
        public IEnumerable<BikeTypeOption> BikeTypes { get; private set; }
        public IEnumerable<FrameSizeOption> FrameSizes { get; private set; }
        public IEnumerable<PartsGroupOption> PartsGroups { get; private set; }
        public IEnumerable<ExtrasOption> Extras { get; private set; }
        #endregion

        #region Private Properties
        private IDataStore dataStore { get; set; }
        #endregion

        #region Constructors
        public BikeOptionService(IDataStore dataStore)
        {
            this.dataStore = dataStore;
        }
        #endregion

        #region Public Methods (Retrieval)
        public IResult GetAvailableBikeTypes()
        {
            return new ActionResult(
                (actionResult) =>
                {
                    this.BikeTypes = dataStore.GetAll<BikeTypeOption>();
                    actionResult.SetComplete(null);
                });
        }

        public IResult GetAvailableFrameSizes()
        {
            return new ActionResult(
                (actionResult) =>
                {
                    this.FrameSizes = dataStore.GetAll<FrameSizeOption>();
                    actionResult.SetComplete(null);
                });
        }

        public IResult GetAvailablePartsGroups()
        {
            return new ActionResult(
                (actionResult) =>
                {
                    this.PartsGroups = dataStore.GetAll<PartsGroupOption>();
                    actionResult.SetComplete(null);
                });
        }

        public IResult GetAvailableExtras()
        {
            return new ActionResult(
                (actionResult) =>
                {
                    this.Extras = dataStore.GetAll<ExtrasOption>();
                    actionResult.SetComplete(null);
                });
        }
        #endregion

        #region Public Methods (Add)
        public IResult Add(params BikeTypeOption[] bikeTypes)
        {
            return new ActionResult(
                (actionResult) =>
                {
                    dataStore.AddRange<BikeTypeOption>(bikeTypes);
                    actionResult.SetComplete(null);
                });
        }

        public IResult Add(params FrameSizeOption[] frameSizes)
        {
            return new ActionResult(
                (actionResult) =>
                {
                    dataStore.AddRange<FrameSizeOption>(frameSizes);
                    actionResult.SetComplete(null);
                });
        }

        public IResult Add(params PartsGroupOption[] partsGroups)
        {
            return new ActionResult(
                (actionResult) =>
                {
                    dataStore.AddRange<PartsGroupOption>(partsGroups);
                    actionResult.SetComplete(null);
                });
        }

        public IResult Add(params ExtrasOption[] extras)
        {
            return new ActionResult(
                (actionResult) =>
                {
                    dataStore.AddRange<ExtrasOption>(extras);
                    actionResult.SetComplete(null);
                });
        }
        #endregion

        #region Public Methods (Clear Data)
        public IResult ClearData()
        {
            return new ActionResult(
                (actionResult) =>
                {
                    dataStore.ClearData<BikeTypeOption>();
                    dataStore.ClearData<FrameSizeOption>();
                    dataStore.ClearData<PartsGroupOption>();
                    dataStore.ClearData<ExtrasOption>();
                    actionResult.SetComplete(null);
                });
        }
        #endregion
    }
}
